#include "Shader.h"
#include <string>

//	__________ Konstrucktoren __________
Shader::Shader(void)
{
}

Shader::Shader(const char* vertex_file_path, const char* fragment_file_path)
{
	id = LoadShaders(vertex_file_path, fragment_file_path);
}

Shader::~Shader(void)
{
}

char * Shader::getName()
{
	return name;
}

void Shader::createHandle(const char * name, const char * nameInShader)
{
	Handle newHandle = {name, nameInShader, getHandleFor(nameInShader)};
	
	allHandles.push_back(newHandle);

	std::cout << "Handle(" << newHandle.name << ", " << newHandle.nameInShader << ", " << newHandle.id << ")" << std::endl;
}

GLuint Shader::getHandle(const char * name)
{
	std::string sname = name;
	for (Handle h : allHandles)
	{
		std::string sHname = h.name;

		if(sHname == sname)
		{
			//std::cout << name << " gefunden!" << std::endl;
			return h.id;
		}
	}
	return NULL;
}

void Shader::use()
{
	glUseProgram(id);
}

void Shader::deleteShader()
{
	glDeleteProgram(id);
}

GLuint Shader::getHandleFor(const char* varName)
{
	return glGetUniformLocation(id, varName);
}

//	______ Setter & Getter _______
GLuint Shader::getId()
{
	return id;
}
